import request from '@/api/request'
import { AxiosPromise } from 'axios'

enum API {
    BASE_URL = "/system/dicts",
    ITEMS_URL = "/system/dict-items"
}

export const searchDictApi = (query:any): AxiosPromise<any> => {
    return request.get<any>(API.BASE_URL+'/search',{
        params: query
    })
}

export const getDictItemsByDictValueApi = (dictValue:string): AxiosPromise<any> => {
    return request.get<any>(API.ITEMS_URL+'/dict-value/'+dictValue)
}

export const createDictApi = (data: any): AxiosPromise<any> => {
    return request.post<any>(API.BASE_URL, data)
}

export const updateDictApi = (data:any): AxiosPromise<any> => {
    return request.put<any>(API.BASE_URL, data)
}

export const deleteDictByIdApi = (id: string|number): AxiosPromise<any> => {
    return request.delete<any>(API.BASE_URL + '/' + id)
}

export const searchDictItemApi = (query:any): AxiosPromise<any> => {
    return request.get<any>(API.ITEMS_URL+'/search',{
        params: query
    })
}

export const createDictItemApi = (data: any): AxiosPromise<any> => {
    return request.post<any>(API.ITEMS_URL, data)
}

export const updateDictItemApi = (data: any): AxiosPromise<any> => {
    return request.put<any>(API.ITEMS_URL, data)
}

export const deleteDictItemByIdApi = (id: string|number): AxiosPromise<any> => {
    return request.delete<any>(API.ITEMS_URL + '/' + id)
}